<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户">
              <j-search-select-tag placeholder="请选择用户" v-model="queryParam.sysUserId" dict="sys_user,realname,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="自习室">
              <j-dict-select-tag placeholder="请选择自习室" v-model="queryParam.zixishiId" dictCode="sr_zixishi,name,id"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="区域">
                <j-dict-select-tag placeholder="请选择区域" v-model="queryParam.quyuId" dictCode="sr_quyu,name,id"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="名称">
                <a-input placeholder="请输入名称" v-model="queryParam.couponName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="使用状态">
                <j-dict-select-tag placeholder="请选择使用状态" v-model="queryParam.useStatus" dictCode="coupon_use_status"/>
              </a-form-item>
            </a-col>
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="创建时间">
                <j-date :show-time="true" date-format="YYYY-MM-DD" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'mycoupon:add'" @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button v-has="'mycoupon:add'" type="primary" icon="download" @click="handleExportXls('我的优惠券')">导出</a-button>

      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
     <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-has="'mycoupon:edit'" @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-has="'mycoupon:delete'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <my-coupon-modal ref="modalForm" @ok="modalFormOk"></my-coupon-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import MyCouponModal from './modules/MyCouponModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { colAuthFilter } from "@/utils/authFilter"
  export default {
    name: 'MyCouponList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      MyCouponModal
    },
    data () {
      return {
        description: '我的优惠券管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'用户',
            align:"left",
            dataIndex: 'sysUserId_dictText'
          },
          {
            title:'电话',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'自习室',
            align:"center",
            dataIndex: 'zixishiId_dictText'
          },
          {
            title:'区域',
            align:"left",
            dataIndex: 'quyuId_dictText'
          },
          {
            title:'名称',
            align:"left",
            dataIndex: 'couponName'
          },
          {
            title:'原金额',
            align:"center",
            dataIndex: 'origAmt'
          },
          {
            title:'优惠金额',
            align:"center",
            dataIndex: 'disAmt'
          },
          {
            title:'有效期开始时间',
            align:"center",
            dataIndex: 'effectStartDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'有效期结束时间',
            align:"center",
            dataIndex: 'effectEndDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'截止日期',
            align:"center",
            dataIndex: 'endDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'开始使用时间',
            align:"center",
            dataIndex: 'useStartTime'
          },
          {
            title:'结束使用时间',
            align:"center",
            dataIndex: 'useEndTime'
          },
          {
            title:'使用状态',
            align:"center",
            dataIndex: 'useStatus_dictText'
          },
          {
            title:'使用时间',
            align:"center",
            dataIndex: 'useTime'
          },
          {
            title:'时长',
            align:"center",
            dataIndex: 'duration'
          },
          {
            title:'剩余时长',
            align:"center",
            dataIndex: 'durationLeft'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'couponType_dictText'
          },
          {
            title:'创建人',
            align:"left",
            dataIndex: 'createBy_dictText'
          },
          {
            title:'创建日期',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'更新日期',
            align:"center",
            dataIndex: 'updateTime'
          },
          {
            title:'多次使用',
            align:"center",
            dataIndex: 'multipleFlag_dictText'
          },
          {
            title:'第三方卡券',
            align:"center",
            dataIndex: 'receiptTitle'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/coupon/myCoupon/list",
          delete: "/coupon/myCoupon/delete",
          deleteBatch: "/coupon/myCoupon/deleteBatch",
          exportXlsUrl: "/coupon/myCoupon/exportXls",
          importExcelUrl: "coupon/myCoupon/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.disableMixinCreated=true;
    this.columns = colAuthFilter(this.columns,'mycoupon:');
    this.loadData();
    this.initDictConfig();
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'sysUserId',text:'用户',dictCode:"sys_user,realname,id"})
        fieldList.push({type:'string',value:'phone',text:'电话',dictCode:''})
        fieldList.push({type:'string',value:'zixishiId',text:'自习室',dictCode:"sr_zixishi,name,id"})
        fieldList.push({type:'string',value:'quyuId',text:'区域',dictCode:"sr_quyu,name,id"})
        fieldList.push({type:'string',value:'couponName',text:'名称',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'origAmt',text:'原金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'disAmt',text:'优惠金额',dictCode:''})
        fieldList.push({type:'date',value:'effectStartDate',text:'有效期开始时间'})
        fieldList.push({type:'date',value:'effectEndDate',text:'有效期结束时间'})
        fieldList.push({type:'datetime',value:'useStartTime',text:'开始使用时间'})
        fieldList.push({type:'datetime',value:'useEndTime',text:'结束使用时间'})
        fieldList.push({type:'datetime',value:'endDate',text:'截止日期'})
        fieldList.push({type:'int',value:'useStatus',text:'使用状态',dictCode:'coupon_use_status'})
        fieldList.push({type:'datetime',value:'useTime',text:'使用时间'})
        fieldList.push({type:'int',value:'duration',text:'时长',dictCode:''})
        fieldList.push({type:'int',value:'couponType',text:'类型',dictCode:'coupon_type'})
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:"sys_user,realname,username"})
        fieldList.push({type:'datetime',value:'createTime',text:'创建时间',dictCode:''})
        fieldList.push({type:'datetime',value:'updateTime',text:'更新时间',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>